#include "expmonth.h"
#include "ui_expmonth.h"
#include<QDebug>
#include<QDesktopWidget>
//This allows to select month or month and year either to view expense record or graph
ExpMonth::ExpMonth(int id,int viewopt,QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ExpMonth)
{
    ui->setupUi(this);
    QRect in=QApplication::desktop()->availableGeometry(this);
    ui->scrollArea->setGeometry(0,0,(in.width()),(in.height()));
    ui->label_header->setFocus();
    ui->verticalLayout->addSpacing(15);
    ui->verticalLayout->setStretch(2,0);
    ui->verticalLayout->setStretch(3,0);
    ui->verticalLayout->setStretch(4,5);
    int fontSize=10;//(in.width()/30.0);
    ui->label_header->setFont(QFont( "lucida", fontSize, QFont::Normal, FALSE ));
    ui->label_months->setFont(QFont( "lucida", (fontSize-2), QFont::Normal, FALSE ));
    ui->label_year->setFont(QFont( "lucida", (fontSize-2), QFont::Normal, FALSE ));
    ui->comboBox_months->setFont(QFont( "lucida", (fontSize-2), QFont::Normal, FALSE ));
    ui->comboBox_years->setFont(QFont( "lucida", (fontSize-2), QFont::Normal, FALSE ));
    ui->pushButton->setFont(QFont( "lucida", (fontSize-2), QFont::Normal, FALSE ));
    filter_id=id;
    viewoption=viewopt;
    if(filter_id==1)//Monthly view
    {
        ui->label_header->setText(tr("Select month and year"));
        this->setWindowTitle(tr("Month And Year"));
    }
    else
    {
        ui->label_header->setText(tr("Select year"));
        this->setWindowTitle(tr("Year"));
        ui->label_months->setVisible(false);
        ui->comboBox_months->setVisible(false);
    }
     QAction* backAction = new QAction( tr("Back"), this );
     backAction->setSoftKeyRole( QAction::NegativeSoftKey );
     connect(backAction, SIGNAL(triggered()), this, SLOT(back()));
     addAction( backAction );
     QStringList list;
     list<<"January"<<"February"<<"March"<<"April"<<"May"<<"June"<<"July"<<"August"<<"September"<<"October"<<"November"<<"December";
     for(int i=0;i<list.size();i++)
         ui->comboBox_months->addItem(list.at(i),Qt::UserRole);
     d=QDate::currentDate();//Set current date
     for(int y=2010;y<=d.year();y++)//2010 till current year
         ui->comboBox_years->addItem(QString("%1").arg(y),Qt::UserRole);
     int find=ui->comboBox_years->findText(QString("%1").arg(d.year()));
     ui->comboBox_years->setCurrentIndex(find);
     find=ui->comboBox_months->findText(QString("%1").arg(list[d.month()-1]));
     ui->comboBox_months->setCurrentIndex(find);



}

ExpMonth::~ExpMonth()
{
    delete ui;
}
void ExpMonth::back()
{
    if(viewoption==1)
    (new ExpView)->show();
    else if(viewoption==2)
        (new Reports)->show();
}

void ExpMonth::on_pushButton_clicked()
{
    if(viewoption==1)
    (new ExpMonthView(filter_id,ui->comboBox_months->currentText(),(ui->comboBox_months->currentIndex()+1),ui->comboBox_years->currentText().toInt()))->show();
    else if((filter_id==1) && (viewoption==2))//show monthly graph
        (new GraphMonthly((ui->comboBox_months->currentIndex()+1),ui->comboBox_years->currentText().toInt()))->show();
    else if((filter_id==2) && (viewoption==2))//Show yearly graph
        (new Graph(ui->comboBox_years->currentText().toInt()))->show();
}

